<!--作者:于大明-->
<template>
    <scroll-view class="conversations" scroll-y="true">
    	<view v-if="conversations.length > 0">
    		<view class="scroll-item" v-for="(conversation, key) in conversations" :key="key">
    			<view class="item-head">
    				<image :src="conversation.data.avatar" class="head-icon"></image>
    				<view class="item-head_unread" v-if="conversation.unread">{{conversation.unread}}</view>
    			</view>
    			<view class="scroll-item_info" @click="navigateToChat(conversation)">
    				<view class="item-info-top">
    					<text class="item-info-top_name">{{conversation.data.name}}</text>
    					<view class="item-info-top_time">{{formatDate(conversation.lastMessage.timestamp)}}</view>
    				</view>
    				<view class="item-info-bottom">
    					<view class="item-info-bottom-item">
    						<view class="item-info-top_content" v-if="!conversation.lastMessage.recalled">
    							<text class="unread-text">{{conversation.lastMessage.read === false && conversation.lastMessage.senderId === currentUser.uuid?'[未读]':''}}</text>
    							<text v-if="conversation.type === 'private'">{{conversation.lastMessage.senderId === currentUser.uuid? '我': conversation.data.name}}:</text>
    							<text v-else>{{conversation.lastMessage.senderId === currentUser.uuid? '我': conversation.lastMessage.senderData.name}}:</text>
    							<text v-if="conversation.lastMessage.type === 'text'">{{conversation.lastMessage.payload.text}}</text>
    							<text v-else-if="conversation.lastMessage.type === 'video'">[视频消息]</text>
    							<text v-else-if="conversation.lastMessage.type === 'audio'">[语音消息]</text>
    							<text v-else-if="conversation.lastMessage.type === 'image'">[图片消息]</text>
    							<text v-else-if="conversation.lastMessage.type === 'file'">[文件消息]</text>
    							<text v-else-if="conversation.lastMessage.type === 'order'">[自定义消息:订单]</text>
    							<text v-else>[[未识别内容]]</text>
    						</view>
    						<view class="item-info-top_content" v-else>
    							<text v-if="conversation.type === 'private'">{{conversation.lastMessage.senderId === currentUser.uuid? '你': `"${conversation.data.name}"`}}撤回了一条消息</text>
    							<text v-if="conversation.type === 'group'">{{conversation.lastMessage.senderId === currentUser.uuid? '你': `"${conversation.lastMessage.senderData.name}"`}}撤回了一条消息</text>
    						</view>
    						<view class="item-info-bottom_action" @click.stop="showAction(conversation)"></view>
    					</view>
    				</view>
    			</view>
    		</view>
    	</view>
    	<view class="no-conversation" v-else>
    		当前没有会话
    	</view>
    	<view class="action-container" v-if="actionPopup.visible">
    		<view class="layer" @click="actionPopup.visible = false"></view>
    		<view class="action-box">
    			<view class="action-item" @click="topConversation">{{actionPopup.conversation.top ? '取消置顶' : '置顶聊天'}}</view>
    			<view class="action-item" @click="deleteConversation">删除聊天</view>
    		</view>
    	</view>
    </scroll-view>
</template>

<script src="./message.js"></script>

<style lang="less" scoped>
    @import url('message.less');
</style>
